package com.itcast.donkey.adapters;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.itcast.donkey.R;
import com.itcast.donkey.activity.InAttackActivity;
import com.itcast.donkey.modles.ScenicAttackModles;

import java.util.ArrayList;


/**
 * Created by lanouhn on 16/8/26.
 */
public class ScenicAttackAdapter extends RecyclerView.Adapter<ScenicAttackAdapter.SpotViewHolder> {

    private Context context;
    private ArrayList<ScenicAttackModles> modlesArrayList;
    private String result;

    public ScenicAttackAdapter(Context context, ArrayList<ScenicAttackModles> modlesArrayList, String result) {
        this.context = context;
        this.modlesArrayList = modlesArrayList;
        this.result = result;
    }

    @Override
    public SpotViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_scenic_attack, null);
        SpotViewHolder holder = new SpotViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final SpotViewHolder holder, final int position) {


        switch (modlesArrayList.get(position).getCategory_type()) {
            case 0:
                holder.ivItemScenicAttack.setImageResource(R.mipmap.tips_overview);
                holder.tvTitleAttack.setText("概览");
                holder.tvTitleEnglish.setText("Overview");
                break;
            case 1:
                holder.ivItemScenicAttack.setImageResource(R.mipmap.tips_note);
                holder.tvTitleAttack.setText("出行须知");
                holder.tvTitleEnglish.setText("Note");
                break;
            case 2:
                holder.ivItemScenicAttack.setImageResource(R.mipmap.tips_arrive);
                holder.tvTitleAttack.setText("如何到达");
                holder.tvTitleEnglish.setText("Arrive");
                break;
            case 3:
                holder.ivItemScenicAttack.setImageResource(R.mipmap.tips_traffic);
                holder.tvTitleAttack.setText("当地交通");
                holder.tvTitleEnglish.setText("Traffic");
                break;
            case 4:
                holder.ivItemScenicAttack.setImageResource(R.mipmap.tips_scenicspots);
                holder.tvTitleAttack.setText("景点");
                holder.tvTitleEnglish.setText("Attraction");
                break;
            case 5:
                holder.ivItemScenicAttack.setImageResource(R.mipmap.tips_entertainment);
                holder.tvTitleAttack.setText("娱乐");
                holder.tvTitleEnglish.setText("Entertainment");
                break;

            case 6:
                holder.ivItemScenicAttack.setImageResource(R.mipmap.tips_stay);
                holder.tvTitleAttack.setText("住宿");
                holder.tvTitleEnglish.setText("Hotel");
                break;
            case 7:
                holder.ivItemScenicAttack.setImageResource(R.mipmap.tips_food);
                holder.tvTitleAttack.setText("美食");
                holder.tvTitleEnglish.setText("Food");
                break;
            case 8:
                holder.ivItemScenicAttack.setImageResource(R.mipmap.tips_shopping);
                holder.tvTitleAttack.setText("购物");
                holder.tvTitleEnglish.setText("Shopping");
                break;
            case 9:
                holder.ivItemScenicAttack.setImageResource(R.mipmap.tips_departure);
                holder.tvTitleAttack.setText("离境须知");
                holder.tvTitleEnglish.setText("Departure");
                break;
            case 11:
                holder.ivItemScenicAttack.setImageResource(R.mipmap.tips_more);
                holder.tvTitleAttack.setText("其他");
                holder.tvTitleEnglish.setText("Other");
                break;
            default:
                holder.ivItemScenicAttack.setImageResource(R.mipmap.wechat_share);
                holder.tvTitleAttack.setText("还没定呢");
                holder.tvTitleEnglish.setText("123");
                break;

        }
        for (int i = 0; i < modlesArrayList.get(position).getPages().size(); i++) {
            holder.textArray.get(i).setText(modlesArrayList.get(position).getPages().get(i).getTitle());
            holder.textArray.get(i).setVisibility(View.VISIBLE);
            if (modlesArrayList.get(position).getPages().size() % 2 == 1) {
                holder.textArray.get(modlesArrayList.get(position).getPages().size()).setVisibility(View.INVISIBLE);
            }
            holder.textArray.get(i).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    try {
                        Intent intent = new Intent();
                        intent.setClass(context, InAttackActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putSerializable("modlesArrayList", modlesArrayList.get(position));
                        //intent.putExtra("result",result);
                        //intent.putExtra("modlesArrayList", modlesArrayList.get(position).getPages().get(0).getTitle());
                        intent.putExtras(bundle);
                        context.startActivity(intent);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }


                }
            });
        }

    }

    @Override
    public int getItemCount() {
        return modlesArrayList.size();
    }

    public class SpotViewHolder extends RecyclerView.ViewHolder {
        private TextView tvTitleFirst;
        private TextView tvTitleSecond;
        private TextView tvTitleThird;
        private TextView tvTitleFourth;
        private TextView tvTitleFifth;
        private TextView tvTitleSix;
        private TextView tvTitleSeven;
        private TextView tvTitleEight;
        private TextView tvTitleNine;
        private TextView tvTitleTen;

        private ImageView ivItemScenicAttack;
        private TextView tvTitleAttack;
        private TextView tvTitleEnglish;

        ArrayList<TextView> textArray = new ArrayList<>();

        public SpotViewHolder(View itemView) {
            super(itemView);
            tvTitleFirst = (TextView) itemView.findViewById(R.id.tv_title_first);
            tvTitleSecond = (TextView) itemView.findViewById(R.id.tv_title_second);
            tvTitleThird = (TextView) itemView.findViewById(R.id.tv_title_third);
            tvTitleFourth = (TextView) itemView.findViewById(R.id.tv_title_fourth);
            tvTitleFifth = (TextView) itemView.findViewById(R.id.tv_title_fifth);
            tvTitleSix = (TextView) itemView.findViewById(R.id.tv_title_six);
            tvTitleSeven = (TextView) itemView.findViewById(R.id.tv_title_seven);
            tvTitleEight = (TextView) itemView.findViewById(R.id.tv_title_eight);
            tvTitleNine = (TextView) itemView.findViewById(R.id.tv_title_nine);
            tvTitleTen = (TextView) itemView.findViewById(R.id.tv_title_ten);

            ivItemScenicAttack = (ImageView) itemView.findViewById(R.id.iv_item_scenic_attack);
            tvTitleAttack = (TextView) itemView.findViewById(R.id.tv_title_attack);
            tvTitleEnglish = (TextView) itemView.findViewById(R.id.tv_title_english);

            textArray.add(tvTitleFirst);
            textArray.add(tvTitleSecond);
            textArray.add(tvTitleThird);
            textArray.add(tvTitleFourth);
            textArray.add(tvTitleFifth);
            textArray.add(tvTitleSix);
            textArray.add(tvTitleSeven);
            textArray.add(tvTitleEight);
            textArray.add(tvTitleNine);
            textArray.add(tvTitleTen);


        }
    }
}
